<?php

class Images {

	public static function listImages() {
		define('IMAGEPATH', 'images/');

		if (is_dir(IMAGEPATH)){
			$handle = opendir(IMAGEPATH);
		} else{
			echo 'No image directory';
		}

		$directoryfiles = array();
		while (($file = readdir($handle)) !== false) {
			if (($file == '.')||($file == '..')) {
				continue;
			}
			$newfile = str_replace(' ', '_', $file);
			rename(IMAGEPATH . $file, IMAGEPATH . $newfile);
			$directoryfiles[] = $newfile;
		}

		foreach($directoryfiles as $directoryfile) {
			if(strpos($directoryfile, '.jpg') || strpos($directoryfile, '.png') || strpos($directoryfile, '.jpeg') || strpos($directoryfile, '.gif')) {
				echo '<li><a href="' . IMAGEPATH . $directoryfile . '" rel="lightbox[varer]">'.$directoryfile.' </a></li>';
			}
		}
		closedir($handle);
	}
}

?>